<%@ page import="com.xinjie.www.service.collect.CollectServiceImpl" %>
<%@ page import="com.xinjie.www.util.Constants" %>
<%@ page import="com.xinjie.www.po.User" %>
<%@ page import="com.xinjie.www.po.Collect" %>
<%@ page import="java.util.List" %>
<%@ page import="com.xinjie.www.service.post.PostServiceImpl" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>收藏</title>
    <style type="text/css">
        table {
            width: 100%;
            border: 1px solid red;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<%
    Object o = request.getSession().getAttribute(Constants.USER_SESSION);
    User user = (User) o;
    CollectServiceImpl collectService = new CollectServiceImpl();
    List<Collect> collects = null;
    try {
        collects = collectService.getCollect(user.getUserId());
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
%>
<div align="center">
    <table>
        <tr>
            <th>收藏id</th>
            <th>帖子id</th>
            <th>收藏时间</th>
            <th></th>
            <th></th>
        </tr>
        <tr>
            <%
                for (Collect collect : collects) {
            %>
            <%="<td>" + collect.getCollectId() + "</td>"%>
            <%="<td>" + collect.getPostId() + "</td>"%>
            <%="<td>" + collect.getTime() + "</td>"%>
            <%
                int post_id = collect.getPostId();
                int collect_id = collect.getCollectId();
            %>
            <td><a href="CollectPost.jsp?postId=<%=post_id%>">查看该帖子</a></td>
            <td><a href="CancelCollect.jsp?collectId=<%=collect_id%>">取消收藏</a></td>
            <%}%>
        </tr>
    </table>
    <a href="UserFrame.jsp">返回</a>
    <%if (request.getSession().getAttribute("cancelSuccess") != null) {%>
    <%=request.getSession().getAttribute("cancelSuccess")%>
    <%request.getSession().removeAttribute("cancelSuccess");%>
    <%
        }
        if (request.getSession().getAttribute("cancelLose") != null) {
    %>
    <%=request.getSession().getAttribute("cancelLose")%>
    <%request.getSession().removeAttribute("cancelLose");%>
    <%}%>
</div>
</body>
</html>
